﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Janus.Windows.Ribbon;
using Lib_general;

namespace HAM
{
    public partial class frmMain : Form
    {
        string s_right="";
        private Struct_Database struc = new Struct_Database();

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //gan_right();
            struc.createschema();
        }
        private void gan_right()
        {
            int n = 0, t = 0;
            bool bx = false;
            for (int i = 0; i < this.ribbon1.Tabs.Count; i++)
            {
                bx = false;

                for (int j = 0; j < this.ribbon1.Tabs[i].Groups.Count; j++)
                {
                    //an group
                    for (int k = 0; k < this.ribbon1.Tabs[i].Groups[j].Commands.Count; k++)
                    {
                        if (this.ribbon1.Tabs[i].Groups[j].Text != "-")
                        {
                            this.ribbon1.Tabs[i].Groups[j].Commands[k].Visible = s_right.IndexOf(this.ribbon1.Tabs[i].Groups[j].MergeOrder.ToString().PadLeft(3, '0') + "+") != -1;
                            if (!bx)
                                bx = this.ribbon1.Tabs[i].Groups[j].Commands[k].Visible;
                        }
                        else
                        {
                            this.ribbon1.Tabs[i].Groups[j].Commands[k].Visible = false;
                        }
                    }
                }
                this.ribbon1.Tabs[i].Visible = bx;
            }
        }
        private TreeNode f_get_menu()
        {
            TreeNode anode, anode1;
            anode = new TreeNode("Tất cả");
            anode.Tag = "menuChucnang";
            anode.Text = "Tất cả";
            foreach (RibbonTab mi in this.ribbon1.Tabs)
            {
                RibbonTab ribbon = (RibbonTab)(mi);

                anode1 = new TreeNode(ribbon.Text.Replace("&", ""));
                //6anode1.Tag = mnuitem.MergeOrder.ToString().PadLeft(3, '0');
                anode.Nodes.Add(anode1);
                if (ribbon1.Tabs.Count > 0)
                {
                    f_Add_Node(anode1, ribbon);
                }

            }
            anode.ExpandAll();
            return anode;
        }

        private void f_Add_Node(TreeNode v_node, RibbonTab ribbon)
        {
            TreeNode anode;
            foreach (RibbonGroup ait in ribbon.Groups)
            {
                RibbonGroup amenu = (RibbonGroup)(ait);
                if (amenu.Text != "-")// && amenu != menuItem8)
                {
                    anode = new TreeNode(amenu.Text.Replace("&", ""));
                    anode.Tag = amenu.MergeOrder.ToString().PadLeft(3, '0');
                    anode.Text = amenu.Text.Replace("&", "");
                    v_node.Nodes.Add(anode);
                    if (amenu.Commands.Count > 0)
                    {
                        f_Add_Node(anode, amenu);
                    }
                }
            }
        }
        private void f_Add_Node(TreeNode v_node, RibbonGroup ribbon)
        {
            TreeNode anode;
            foreach (ButtonCommand ait in ribbon.Commands)
            {
                ButtonCommand amenu = (ButtonCommand)(ait);
                if (amenu.Text != "-")
                {
                    anode = new TreeNode(amenu.Text.Replace("&", ""));
                    anode.Tag = amenu.MergeOrder.ToString().PadLeft(3, '0');
                    anode.Text = amenu.Text.Replace("&", "");
                    v_node.Nodes.Add(anode);                    
                }
            }
        }

        private void buttonCommand3_Click(object sender, Janus.Windows.Ribbon.CommandEventArgs e)
        {
            frmRight_DN f = new frmRight_DN(f_get_menu());
            f.Show();
        }

        private void buttonCommand4_Click(object sender, Janus.Windows.Ribbon.CommandEventArgs e)
        {

        }

        private void commanddmchucvu_Click(object sender, CommandEventArgs e)
        {
            frmDmChucvu f = new frmDmChucvu();
            f.MdiParent = this;
            f.Show();
        }

        private void commanddmnhanvien_Click(object sender, CommandEventArgs e)
        {
            frmDmNhanvien f = new frmDmNhanvien();
            f.MdiParent = this;
            f.Show();
        }

        private void commanddmkho_Click(object sender, CommandEventArgs e)
        {
            frmDmKho f = new frmDmKho();
            f.MdiParent = this;
            f.Show();
        }

        private void commanddmdvt_Click(object sender, CommandEventArgs e)
        {
            frmDmDVT f = new frmDmDVT();
            f.MdiParent = this;
            f.Show();
        }

        private void commanddmsanpham_Click(object sender, CommandEventArgs e)
        {
            
        }

        private void commanddmnhacc_Click(object sender, CommandEventArgs e)
        {
            
        }

        private void commanddmquydoi_Click(object sender, CommandEventArgs e)
        {

        }

        private void commandketthuc_Click(object sender, CommandEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn kết thúc không?", "SYSTEM", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void commandphieunhap_Click(object sender, CommandEventArgs e)
        {
            frmPhieunhap f = new frmPhieunhap();
            f.MdiParent = this;
            f.Show();
            f.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }
    }
}
